/**
 * Created by 준영 on 2014-09-12.
 */

var commonViewModel = (function() {


    Function.prototype.method = function(name, func)
    {
        this.prototype[name] = func;
    };
    function commonViewModel() {

            this.FromList = ko.observableArray();
            this.ToList = ko.observableArray();
    };

    commonViewModel.method("getMessageInfo", function(data)
    {
        var self = this;
        callAjax('GET', '/api/getMessageInfo', { }, function(res)
        {
            $.each(res.fromUser,function(index, element)
            {
                self.FromList.push({"Content": element.Content, "From" : element.From, "To" : element.To});
            });
        });

        // 타이머로 메시지 정보 실시간으로 받아옴
        /* var timer = setInterval(function () {


         }, 3000);

         callAjax('GET', '/api/getMessageCount', { "UserID": user }, function(res)
         {



         });

         callAjax('POST', '/api/sendMessage', { "From": user, "To": "pjy1", "Content" : "안녕하세요1" }, function(res)
         {



         });
         */

    });
    return commonViewModel;
})();
$(function() {
    $( "#MessageTabs" ).tabs({
        activate:function(event,ui){
            var sel = (ui.oldTab)[0];
            var newSel = (ui.newTab)[0];

            $(sel).removeClass('active');

            $(newSel).addClass('active');

            $('#currentState').text(newSel.textContent);

        }
    });
});

$(document).ready(function()
{
    var viewModel = new commonViewModel();
    viewModel.getMessageInfo();


    $('#MessageModal').modal('show');
});